package com.meixiang.adapter.personalCenter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.meixiang.R;
import com.meixiang.activity.account.myShopper.PhotoListShowEvaluateActivity;
import com.meixiang.entity.myOrder.MyOrderDetail;
import com.meixiang.global.GlobalType;
import com.meixiang.util.AbFileUtils;
import com.meixiang.util.GlideHelper;
import com.meixiang.view.photoSelectActivity.activity.PhotoListShowActivity;
import com.meixiang.view.photoSelectActivity.util.Bimp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yinsujun  Created at 2016/7/6 10:48
 */
public class OrderEvaluationPhotoAdapter extends RecyclerView.Adapter<OrderEvaluationPhotoAdapter.ViewHolder> {

    private ArrayList<String> filePath=new ArrayList<>();
    private Context context;
    private String orderName;

    private int photoPosition=-1;

//    private MyOrderDetail.OrderGoodsListBean data=new MyOrderDetail.OrderGoodsListBean();
//    private List<MyOrderDetail.OrderGoodsListBean> data=new ArrayList<>();
    private LayoutInflater inflater;


    public void setPosition(int position) {
        this.photoPosition = position;
    }

    public OrderEvaluationPhotoAdapter(Context context, String orderName) {
        this.context=context;
        inflater = LayoutInflater.from(context);
        this.orderName=orderName;
    }
//    public void addFile(int position,List<String> filePath) {
//        this.filePath.addAll(filePath);
////        this.notifyDataSetChanged();
//        this.notifyItemChanged(position);
//    }
//
//
//    public void addFile(List<String> filePath) {
//        this.filePath=filePath;
//        this.notifyDataSetChanged();
//    }

    public void addPhoto(ArrayList<String> data){
        this.filePath=data;
        this.notifyDataSetChanged();

    }


    public int getCount() {
        return filePath.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_gridview,parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    public void deletePhoto(int position){
        filePath.remove(position);
//        this.notifyItemRemoved(position);
        this.notifyDataSetChanged();
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if(filePath!=null&&filePath.size()>0){
//            holder.image.setImageBitmap(filePath.get(position).getBitmap());
//            holder.image.setTag(filePath.get(position).getImagePath());

            GlideHelper.showImage(context,filePath.get(position),holder.image);
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context,PhotoListShowEvaluateActivity.class);
//                    ArrayList<String> photo = (ArrayList<String>) data.getPhoto();
                    intent.putExtra("position", position);
                    intent.putExtra("title",orderName);
                    intent.putExtra("orderPosition",photoPosition);
                    intent.putStringArrayListExtra("imagePath",filePath);
                    intent.putExtra("photoType", GlobalType.EVALUATE_ORDER_CHECK_PHOTO);
                    context.startActivity(intent);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        if(filePath!=null&&filePath.size()>0){
            return filePath.size();
        }else
            return 0;
    }
    public class ViewHolder  extends RecyclerView.ViewHolder{
        public ImageView image;

        public ViewHolder(View itemView) {
            super(itemView);
            image= (ImageView) itemView.findViewById(R.id.item_grid_image);
        }
    }
}
